<template>
	<el-dialog title="委托对话框" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
			<el-form-item label="流程名称" style="overflow: hidden;white-space: nowrap;text-overflow:ellipsis;">
				{{flowTitle}}
			</el-form-item>
			<el-form-item label="被委托人" prop="accountId">
				<el-select v-model="form.accountId" style="width: 100%">
					<el-option v-for="item in userList" :key="item.accountId" :label="item.userName" :value="item.accountId"></el-option>
				</el-select>
			</el-form-item>
			<msg-box-check-box v-model:msgType="form.msgType" code="doc-change-user"></msg-box-check-box>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">确 定</el-button>
		</template>
	</el-dialog>
</template>

<script>
import msgBoxCheckBox from "@/views/module/msgBoxCheckBox";
export default {
	components: {
		msgBoxCheckBox
	},
	emits: ['success', 'closed'],
	data() {
		return {
			visible: false,
			isSaveing: false,
			flowTitle: '',
			userList:[],
			//表单数据
			form: {
				runId:'',
				stepRunId: '',
				accountId:'',
				msgType:'',
			},
			//验证规则
			rules: {
				accountId: [
					{required: true, message: '被委托人不能为空', trigger: 'blur'}
				]
			}
		}
	},
	mounted() {

	},
	methods: {
		//显示
		open() {
			this.visible = true;
			return this
		},
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					let res = await this.$API.bpm.bpmStepRun.changeBpmStepRunUser.post(this.form);
					this.isSaveing = false;
					if (res.code == 200) {
						this.visible = false;
						this.$emit('success')
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			});
		},
		setData(data)
		{
			this.flowTitle=data.flowTitle;
			this.form.runId = data.runId;
			this.form.stepRunId=data.stepRunId;
			this.getDelegateUserList();
		},
		async getDelegateUserList()
		{
			var res = await this.$API.bpm.bpmDelegate.getDelegateUserList.get({runId:this.form.runId,stepRunId:this.form.stepRunId});
			if (res.code == 200) {
				this.userList = res.data;
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		}
	}
}
</script>

<style>
</style>
